/**
 * 解析路径地址字符串转为 location 对象 (与 createPath 方法相反)
 * @param {*} path 路径地址
 * @returns 
 */
export function parsePath(path) {
    let pathname = path || '/';
    let search = '';
    let hash = '';
    // hash 位置(#后面有?也是哈希内容)
    let hashIndex = pathname.indexOf('#');
    if (hashIndex !== -1) {
        hash = pathname.substr(hashIndex);
        pathname = pathname.substr(0, hashIndex);
    }
    // 查询参数位置
    let searchIndex = pathname.indexOf('?');
    if (searchIndex !== -1) {
        search = pathname.substr(searchIndex);
        pathname = pathname.substr(0, searchIndex);
    }
    return {
        pathname,
        search: search === '?' ? '' : search,
        hash: hash === '#' ? '' : hash
    };
}